import requests
from ronglian_sms_sdk import SmsSDK
#
from celery_tasks.main import app

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest


# 容联云的发送短信方式
@app.task
def send_messages(mobile, code):
    accID = '2c94811c8a27cf2d018a3ef7bcf6076e'
    accToken = '5bf4960e30f94e3c928dbf814bd73f7e'
    appID = '2c94811c8a27cf2d018a3ef7be420775'
    sdk = SmsSDK(accID, accToken, appID)
    datas = (code, '2')
    res = sdk.sendMessage('1', mobile, datas)
    print(res)
#
#
#
#
#
# # 这是使用国阳云发送短信的一个方法
@app.task
def sms_code(mobile, code):
    url = "https://gyytz.market.alicloudapi.com/sms/smsSend"
    appcode = 'c541727433b743838b0273d31b0d70c3'
    smsSignId = "47c90694a5174e5d9b88186600ccc413"
    templateId = "1a159d91f29942a7b791508880ed9b50"
    param = f'**code**:{code},**minute**:5'
    # smsSignId（短信前缀）和templateId（短信模板），可登录国阳云控制台自助申请。参考文档：http://help.guoyangyun.com/Problem/Qm.html
    data = {"mobile": mobile, "smsSignId": smsSignId, "templateId": templateId, "param": param}
    headers = {"Content-Type": "application/x-www-form-urlencoded", "Authorization": "APPCODE " + appcode}
    response = requests.post(url, headers=headers, params=data)
    print(response)



